Example to illustrate the usage of Analog Converter modules in BinPy.


In [1]:
from BinPy import *

Analog to Digital Converter module - A2D


In [2]:
# Initiating the input analog Bus
input_analog = Bus(Connector(voltage = 3.2))
input_analog.set_type(analog=True)

In [3]:
# Initiating the output digital Bus
output_digital = Bus(16)

# Building the power supply
VREF = Connector(voltage = 5.0)
GND = Connector(voltage = 0)

In [4]:
# Initializing the A2D converter
a2d_16bit = A2D(input_analog, output_digital, 3, VREF, GND, scale=0.5 )

In [5]:
time.sleep(0.5) # Setup time
print output_digital.get_logic_all(as_list = False)


0b0101000111101011

In [6]:
# Varying the input
input_analog[0].set_voltage(3.2)
time.sleep(0.5) # To allow conversion to take place.

In [7]:
print output_digital.get_logic_all(as_list = False)


0b0101000111101011

In [8]:
# 64 Bit A2D Converter
ieee_64bit = Bus(64)
a2d_IEEE64 = A2D(input_analog, ieee_64bit, 5)
time.sleep(0.5) # To allow conversion to take place.
print ieee_64bit.get_logic_all(as_list = False)


0b0100000000001001100110011001100110011001100110011001100110011010

Digital to Analog Converter module - D2A


In [9]:
# Output Bus-es
output_of_D2A   = Bus(Connector(voltage = 0.0))
output_of_D2A.set_type(analog = True)

# Input Bus
input_digital = output_digital # The input_digital refers to the output_digital, the output of the A2D of the last section

In [10]:
d2a_16bit = D2A(input_digital, output_of_D2A, 3, VREF, GND, scale = 2)
time.sleep(0.1) # Setup time

In [11]:
print output_of_D2A[0].get_voltage()


3.1999206543

In [12]:
ieee_packed = Bus(1)
ieee_packed.set_type(analog = True)
d2a_ieee64 = D2A(ieee_64bit, ieee_packed, 5) # Setting the input from the output of the previous A2D Block
time.sleep(0.1) # Setup time

In [13]:
print  ieee_packed[0].get_voltage()


3.2